#ifndef VERIFYCODEWIDGET_H
#define VERIFYCODEWIDGET_H

#include <QWidget>
#include<QRandomGenerator>
#include <QMouseEvent>

class VerifyCodeWidget : public QWidget
{
    Q_OBJECT
public:
    explicit VerifyCodeWidget(QWidget *parent = nullptr);

    QString generateVerifyCode(); // 生成随机的验证码字符串
    void refreshVerifyCode(); // 刷新验证码并显示到界面上
    bool checkVerifyCode(const QString& input) const;   // 校验输入

protected:
    void paintEvent(QPaintEvent* event) override;
    // 用户点击的时候, 刷新验证码, 并重新显示.
    void mousePressEvent(QMouseEvent* event) override;

private:
    QRandomGenerator randomGenerator; // 随机数生成器
    QString verifyCode = ""; // 保存验证码的值

};

#endif // VERIFYCODEWIDGET_H
